const game = @import("./game.zig");
const ecs = @import("ecs");
const rl = @import("raylib");
const prefabs = @import("./prefabs.zig");
const components = @import("./components.zig");
const Game = game.Game;
const System = @import("./system.zig");

pub const DrawSystem = struct {
    const Self = @This();
    view: ecs.MultiView(.{ components.Translation, components.Scale, components.Rotate }, .{}),
    reg: *ecs.Registry,

    pub fn init(reg: *ecs.Registry) Self {
        return .{
            .view = reg.view(.{ components.Translation, components.Scale, components.Rotate }, .{}),
            .reg = reg,
        };
    }
    pub fn run(self: *anyopaque) void {
        const ds: *DrawSystem = @ptrCast(@alignCast(self));
        var iter = ds.view.entityIterator();
        while (iter.next()) |ent| {
            const tran = ds.view.getConst(components.Translation, ent);

            rl.drawRectangle(@intFromFloat(tran.x), @intFromFloat(tran.y), 50, 50, rl.Color.red);
        }
    }
    pub fn system(self: *Self) System {
        return .{
            .ptr = self,
            .vtable = .{
                .run = Self.run,
            },
        };
    }
};
